﻿using System;
using System.Linq;
using System.Transactions;
using NUnit.Framework;
using ProjetoComperio.BusinessLogicLayer;
using ProjetoComperio.DataLayer.Entities;
using ProjetoComperio.Test.FakeData;

namespace ProjetoComperio.Test.BusinessLogicLayer
{
    [TestFixture]
    public class EducationalITApplicationBLLTest
    {
        EducationalITApplicationBLL educationalITApplicationBLL;

        [TestFixtureSetUp]
        public void TestFixtureSetUp()
        {

            educationalITApplicationBLL = new EducationalITApplicationBLL();
        }

        [SetUp]
        public void SetUp()
        {
            educationalITApplicationBLL.InitializeDataContext(new FakeComperioEntitiesDataModel());
        }
        [Test]
        public void TestRetrieveEducationITApplications()
        {
            Assert.AreEqual(7, educationalITApplicationBLL.RetrieveEducationalITApplications().Count());
        }

        [Test]
        [Category("lazy")]
        public void TestCreateEducationalITApplication_Valid()
        {
           using (TransactionScope transactionScope = new TransactionScope())
            { 
                Student student = StudentBLLTest.CreateFakeStudent();
                String password = "1234ABCD_90s";
                string UserName = "ASHD_87s";

                StudentBLL studentBLL = new StudentBLL();
                studentBLL.Create(student, UserName, password);

                EducationalITApplication educationalItApplication = new EducationalITApplication
                {
                    AcademicPerson = student,
                    AcademicPersonID = student.PersonID,
                    Title = "title",
                    RegisterDate = DateTime.Now,
                    SourceInfo = "sourceInfo",
                    AdditionalInfo = "ai",
                    Description = "description",
                    UseInstructions = "UseInstructions",
                    IsFree = true,
                    IsOpenSource = true
                };

                EducationalITApplicationBLL educationalItApplicationBLL = new EducationalITApplicationBLL();

                educationalItApplicationBLL.Create(educationalItApplication);

                var storedEducationalITApplication =
                    educationalItApplicationBLL.RetrieveEducationalITApplications().Where(app => app.Title.ToLower() == "title").FirstOrDefault();

                Assert.IsTrue(storedEducationalITApplication.RegisterDate.Date == DateTime.Now.Date);


                transactionScope.Dispose();
            }
        }
    }
}
